<template>
  <div class="ke">
    <div class="center">
      <left></left>
      <div class="right">
        <top></top>
        <div class="hei10"></div>

        <div style="padding: 20px;">
          <div @click="$router.back()" style="margin-bottom: 20px; cursor: pointer;"><i class="el-icon-back" style="color: rgb(57, 91, 255); margin-right: 10px; font-size: 20px; font-weight: bold;"></i>返利领取导出记录</div>

          <div class="kflexc">
            <el-upload ref="upload" action="#" :http-request="(params) => uploasd2(params)" :show-file-list="false">
               <el-button type="danger" round plain >导入充值结果</el-button>
            </el-upload>

            <el-button type="text" @click="xiazaimoban()">下载导入模板</el-button>
          </div>


          <el-table :data="list" border style="width: 100%; margin: 20px 0;">
            <el-table-column align='center' prop='operator' label="操作人"></el-table-column>
            <el-table-column align='center' prop='created_at' label="导出时间"></el-table-column>
            <el-table-column align='center' prop='success_nums' label="导出订单数"></el-table-column>
            <el-table-column align='center' label="操作" width="550px">
              <template slot-scope="scope" >
                <div class="kflexcc">
                  <el-button type="text" @click="xiazai2(scope.row)">下载记录</el-button>
                  <span style="margin: 0 10px;" v-if="scope.row.import_file">已充值</span>
                  <el-button type="text" v-if="scope.row.import_file" @click="xiazai(scope.row)">下载充值结果</el-button>

                  <el-upload ref="upload" action="#" :http-request="(params) => uploasd(params,scope.row)" :show-file-list="false">
                     <el-button type="text" round style="margin-right: 20px;">上传充值结果</el-button>
                  </el-upload>
                </div>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination style="text-align: right;" background layout="total,prev, pager, next" :current-page="all.page" @current-change="fanye" :page-size="all.page_size" :total="total"></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import axios from 'axios'
  import top from '@/components/top.vue'
  import left from '@/components/left.vue'
  import foot from '@/components/foot.vue'
  import moment from "moment";
  import XLSX from 'xlsx';
  import {
      read,utils
    } from 'xlsx'

  export default {
    components: {
      "left": left,
      "top": top,
      "foot": foot
    },
    name: "ke",
    data() {
      return {
        times:[],
        loading:false,
        list:"",
        all:{
          page:1,
          page_size:20
        },
        log:false,
        total:0,
        id:""
      }
    },
    created() {
      this.getlist()
    },
    mounted() {

    },
    methods: {
      xiazaimoban:function(){
        const a = document.createElement('a');
        a.setAttribute('download', '导入充值结果.xlsx');
        a.setAttribute('href', location.origin + location.pathname + 'static/moban/daoruchongzhijieguo.xlsx');
        a.click();
      },

      xiazai:function(item){

        const a = document.createElement('a');
        a.setAttribute('download', '下载充值结果.xlsx');
        a.setAttribute('href', item.import_file);
        a.click();

      },
      xiazai2:function(item){

        const a = document.createElement('a');
        a.setAttribute('download', '下载记录.xlsx');
        a.setAttribute('href', item.local_filename);
        a.click();
      },

      uploasd2(file,item) {
        console.log(file)
        console.log(item)
        let obj = new FormData()
        obj.append("file", file.file)
        axios.post('/api/plan-market/fanli/result/imp/all',obj)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message.success('导入成功');
              this.getlist()
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },

      uploasd(file,item) {
        console.log(file.file)
        console.log(item)
        let obj = new FormData()
        obj.append("file", file.file)
        obj.append("id", item.id)
        axios.post('/api/plan-market/fanli/result/imp',obj)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message.success('导入成功');
              this.getlist()
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //导出
      daochu: function() {
        axios.post('/api/plan-market/fanli/rebate/export')
          .then(response => {
            if (response.data.msg.code == 0) {
              location.href = response.data.data
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      search: function() {
        this.all.page = 1
        this.getlist()
      },
      //翻页
      fanye: function(page) {
        this.loading = true
        this.all.page = page
        this.getlist()
      },
      //获取列表
      getlist: function() {
        axios.get(`/api/plan-market/export/log3`,{params:this.all})
          .then(response => {
            if (response.data.msg.code == 0) {
              this.list = response.data.data.data
              this.total = response.data.data.total
              this.loading = false
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },

    }
  }
</script>

<style lang="scss" scoped>
  .ke {
    .powertop {
    	display: flex;
    	background:#f9f9f9;
    }
    .powertopli {
    	flex-basis: 180px;
    	line-height: 50px;
    	border-bottom: 3px #F9F9F9 solid;
    	color: #727272;
    	border-right: 1px #F9F9F9 solid;
    	font-size: 16px;
    	text-align: center;
    }
    .router-link-active {
    	background: #FFFFFF;
    	border-bottom: 3px #2974FF solid;
    }
    /deep/ .el-pagination.is-background .btn-prev:disabled{ background: rgba(246, 246, 246, 0.3); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .el-pagination.is-background .btn-next:disabled{ background: rgba(246, 246, 246, 0.3); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .el-pagination.is-background .btn-next{ background: rgba(246, 246, 246,1); border: 1px rgba(167, 167, 167,1) solid;}
    /deep/ .el-pagination.is-background .btn-prev{ background: rgba(246, 246, 246,1); border: 1px rgba(167, 167, 167,1) solid;}
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active{ background-color: #2974FF;}
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active:hover {
        color: #fff;
    }
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled):hover {
        color: #2974FF;
    }
    /deep/ .el-pager li{ border-radius: 14px; background: rgba(255, 255, 255, 1); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .btn-prev{ border-radius: 14px; padding: 0 10px;}
    /deep/ .btn-next{ border-radius: 14px; padding: 0 10px;}

    /deep/ .el-table th{ background: rgb(246, 246, 246);}
    /deep/ .el-input__inner{ line-height: 36px; height: 36px; font-size: 12px; background: rgb(247, 248, 250);  border: 0;}
    /deep/ .el-date-editor .el-range-input{ background: rgb(247, 248, 250); }
    /deep/ .el-button{ padding: 11px 23px !important;}
    /deep/ .el-button--mini{ padding: 6px 15px !important;}
    /deep/ .el-button--danger {
        color: #FFF;
        background-color: #2974FF;
        border-color: #2974FF;
    }
    .team {
    	background: #F9F9F9;
    }
  }
</style>
